﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Web.Routing;

namespace ProjectBase.Core.Web
{
    /// <summary>
    ///     Description for every Action
    /// </summary>
    public class ActionItem : IActionItem
    {
        #region
        RouteValueDictionary _routeValues = new RouteValueDictionary();
        string _text;
        #endregion

        #region IActionItem Members
        /// <summary>
        ///     Name which identifies actionItem by action name
        /// </summary>
        public virtual string ActionName { get; set; }

        /// <summary>
        ///     Controller on which is Action hosted
        /// </summary>
        public virtual string ControllerName { get; set; }

        /// <summary>
        ///     The value (if any) which should be pass as parameter
        ///     (it is an abbreviation for the RouteValues["id"] = ActionValue)
        /// </summary>
        public virtual string ActionValue
        {
            get
            {
                if (RouteValues.ContainsKey(Constants.Common.RouteValuesId))
                {
                    return RouteValues[Constants.Common.RouteValuesId].ToString();
                }
                return null;
            }
            set { RouteValues[Constants.Common.RouteValuesId] = value; }
        }

        /// <summary>
        ///     Extend the Path with key-pair values.
        ///     If ActionValue.Is(), then is converted into the { id = ActionValue }.
        ///     Default is instantiaged empty dictionary
        /// </summary>
        public virtual RouteValueDictionary RouteValues
        {
            get { return _routeValues; }
            set { _routeValues = value; }
        }

        /// <summary>
        ///     String key which should be used for Localization.
        ///     This is used if string.IsNullOrEmpty(TextLocalized).
        ///     (when not provided, Action Name is used)
        /// </summary>
        public virtual string Text
        {
            get
            {
                return _text.IsNull()
                           ? ActionName
                           : _text;
            }
            set { _text = value; }
        }

        /// <summary>
        ///     Already localized and Text for user
        /// </summary>
        public virtual string TextLocalized { get; set; }

        /// <summary>
        ///     Where should the anchor navigate to
        /// </summary>
        public virtual string Href { get; set; }

        /// <summary>
        ///     What target for anchor should be used.
        ///     if string.IsNullOrEmpty(Target) current is used
        /// </summary>
        public virtual string Target { get; set; }

        /// <summary>
        ///     If TextLocalized is empty, Title is rendered
        ///     More detailed description for this action. Value will be localized
        ///     (See TitleLocalized).
        /// </summary>
        public virtual string Title { get; set; }

        /// <summary>
        ///     The more descriptive value of current action - localized.
        /// </summary>
        public virtual string TitleLocalized { get; set; }
        #endregion
    }
}